## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
from waflib import Options

required_python_modules = [
    'gtk',
    'goocanvas',
    'pygraphviz',
    ]

def configure(conf):
    # If Python was explicitly disabled, then add this module to the
    # list of modules that won't be built if they are enabled.
    conf.env['ENABLE_PYVIZ'] = True
    if not conf.check_optional_feature("python"):
        conf.env['ENABLE_PYVIZ'] = False
        conf.report_optional_feature("PyViz", "PyViz visualizer",
                                     False,
                                     "Python Bindings are needed but not enabled")
        conf.env['MODULES_NOT_BUILT'].append('visualizer')
        return

    modules_missing = []
    for pymod in required_python_modules:
        try:
            conf.check_python_module(pymod)
        except conf.errors.ConfigurationError:
            modules_missing.append(pymod)
    if modules_missing:
        conf.report_optional_feature("PyViz", "PyViz visualizer",
                                     False, "Missing python modules: %s" % (', '.join(modules_missing),))
        conf.env['ENABLE_PYVIZ'] = False
        conf.env['MODULES_NOT_BUILT'].append('visualizer')
        return

    conf.report_optional_feature("PyViz", "PyViz visualizer", True, None)


def build(bld):

    module = bld.create_ns3_module('visualizer', ['internet', 'wifi', 'point-to-point'])
    headers = bld(features='ns3header')
    headers.module = 'visualizer'

    # Don't do anything more for this module if Python was explicitly
    # disabled.
    if not bld.env['ENABLE_PYVIZ']:
        return


    headers.source = []

    # XXX This file was added so that static builds would work on
    # Darwin, which doesn't like modules with no source files.  It
    # would have been better to add this module to the list
    # conf.env['MODULES_NOT_BUILT'] if Python bindings were not
    # enabled, but it's not possible for this module to determine in
    # its configure() function if Python bindings will be enabled
    # because that is done by the wscript file in bindings/python that
    # is parsed after this module's wscript file is parsed.
    module.source = [
        'model/dummy-file-for-static-builds.cc',
        ]

    module.features += ' pyembed'
    #module.env.append_value('CXXFLAGS', module.env['shlib_CXXFLAGS'])
    #module.includes = '.'

    module.source.extend([
        'model/pyviz.cc',
        'model/visual-simulator-impl.cc',
        ])
    headers.source.append('model/pyviz.h')

    vissrc = [
        'visualizer/base.py',
        'visualizer/core.py',
        'visualizer/higcontainer.py',
        'visualizer/hud.py',
        'visualizer/__init__.py',
        'visualizer/svgitem.py',
        ]
    pyviz = bld(features='py')
    pyviz.source = vissrc
    pyviz.install_path = '${PYTHONARCHDIR}/visualizer'

    visplugin_src = [
        'visualizer/plugins/interface_statistics.py',
        'visualizer/plugins/ipv4_routing_table.py',
        'visualizer/plugins/olsr.py',
        'visualizer/plugins/show_last_packets.py',
        'visualizer/plugins/wifi_intrastructure_link.py'
        ]
    pyvizplug = bld(features='py')
    pyvizplug.source = visplugin_src
    pyvizplug.install_path = '${PYTHONARCHDIR}/visualizer/plugins'

    bld.ns3_python_bindings()
